#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int snakesAndLadders(vector<vector<int>> &board)
    {
        int n = board.size();
        vector<int> path(n * n + 1);
        vector<int> curPath{1};
        for (int step = 0; !curPath.empty(); step++)
        {
            auto temp = curPath;
            curPath.clear();
            for (int x : temp)
            {
                if (x == (n * n))
                {
                    return step;
                }
                for (int y = x + 1; y <= min(n * n, x + 6); ++y)
                {
                    int row = (y - 1) / n;
                    int col = (y - 1) % n;
                    if (row % 2 != 0)
                    {
                        col = (n - col - 1);
                    }
                    int curLocation = board[n - row - 1][col];
                    if (curLocation < 0)
                    {
                        curLocation = y;
                    }
                    if (!path[curLocation])
                    {
                        path[curLocation] = true;
                        curPath.push_back(curLocation);
                    }
                }
            }
        }
        return -1;
    }
};

int main()
{
    return 0;
}